
//规则条件列表js代码块
var SysDictListPage = {
		
		//初始化一些东西
		init : function(){
			
		},
		
		 /*创建分页实例current*/
	    pagingTooler : new PagingTooler({
	        callbackMethodName : "SysDictListPage.findSysDictList",
	        pageSize : 10,
	        firstPageBtnID : "firstPageBtn",
	        lastPageBtnID : "lastPageBtn",
	        pageCodeLayerID : "pageCodeLayer",
	        recordListLayerID : "dataListLayer",
	        showCurrentPageLayerID : "currentPageLayer",
	        showRecordCountLayerID : "recordCountLayer",
	        showPageCountLayerID : "pageCountLayer",
	        showLoadingLayerID : "loadingLayer",
	        showNoRecordLayerID : "recordLayer",
	        pagingToolbarLayerID : "pagingToolbarLayer",
	        pageSizeSelectLayerID : "pageSizeSelectLayer",
	        jumpPageCodeInputID : "pageInput",
	        jumpPageBtnID : "goPageBtn",
	        pageSizeArray : [10,15,20],
	        hideColumnLayerID : "hideColumnLayer",   //隐藏列div的ID
	    }),
	    
	    search : function(){
	    	var forms = $(".searchParameter");
			var params = {};
			for(var i = 0 ; i < forms.length; i ++){
				var form = $(forms[i]);
				var id = form.attr("id");
				id = id.replace("search_","");
				var value = $.trim(form.val());
				if(value == "") continue;
				params[id] = value;
			}
			
			this.pagingTooler.search(params);
			
	    },
	    
	    findSysDictList : function(){
	    	
	    	var params = this.pagingTooler.getPagingAndSearchParams();
	    	
	     	$.ajax({
			 	url : '/sysDict/findSysDictList',
			 	type :'POST',
			 	data : JSON.stringify(params),
			 	dataType : "json",
			 	contentType : 'application/json; charset=UTF-8',
			 	success:function(data){
			 		var count = data.data.total;
			 		var dataList = data.data.list;
			 		var txt = "";
			 		SysDictListPage.dataList = dataList;
			 		for(var i = 0 ; dataList != null && i < dataList.length ; i ++){
			 			txt +=SysDictListPage.createRecordTxt(dataList[i], i)
			 		}
			 		SysDictListPage.pagingTooler.showInPage(count, txt,"currentNumberPage");
			 	}		
			 });

	    },
	    
	    //创建表格中每一条记录的文本
	    createRecordTxt : function(data , index){
	    	
	    	var txt = "";
	    	  
			txt = '<tr>'+
						'<td><input type="checkbox" class="checkitem"/></td>'+
						'<td>'+CommonUtil.fillBlank(data.typeCnName)+'</td>'+
						'<td>'+CommonUtil.fillBlank(data.type)+'</td>'+
						'<td>'+CommonUtil.fillBlank(data.business)+'</td>'+
	    				'<td>'+
		    				'<button onclick="SysDictListPage.popEditSysDictWindow('+index+')"  class="btn btn-mini">配置</button>&nbsp;'+
    					'</td>'+
	    			  '</tr>';
	    	return txt;
	    },
	    
	    //弹出编辑窗口
	    popEditSysDictWindow : function(index){
	     	
	     	//当前编辑对象
	    	this.currentUpdateRecord = this.dataList[index];
	    	
	    	var currentUpdateRecord = this.currentUpdateRecord;
	    	
	    	//显示弹窗
	     	$('#editSysDictWindow').attr("editId" , currentUpdateRecord.id).modal();
	     	
	     	for(var key in currentUpdateRecord){
	     		
	     		var value = currentUpdateRecord[key];
	     		
	     		if(key == "birthday" && value && value != "" && value != null){
	     			$("#edit_" + key).val(CommonUtil.getDateYmd(new Date(value)));
	     		}else{
	     			$("#edit_" + key).val(value);
	     		}
	     		
	     	}
	     	
	    },
	    
	  //获取编辑窗口的表单参数
      getUpdateSysDictFormParams : function(){
	    	
	    	var params = {};
	    	
			
	    	return params;
	    	
	    },
	    
	    //校验新增的参数
	    validateUpdateSysDictFormParams : function(params){
	    	
	    	//校验的逻辑自己填写,返回true和false,可以弹出一些提示
	    	return true;

	    },
	    
	    //更新
	    updateSysDict : function(){
	    	
	    	var params = this.getUpdateSysDictFormParams();
	    	
	    	//校验不通过,直接返回
	    	if(!this.validateUpdateSysDictFormParams(params)) return;
	    	
	    	$.ajax({
			 	url : '/sysDict/updateSysDict',
			 	type :'POST',
			 	data : JSON.stringify(params),
			 	
			 	beforeSend : function(){
			 		$("#addSysDictBtn").attr("disabled","disabled");
			 	},
			 	complete: function(){
			 		$("#addSysDictBtn").removeAttr("disabled","disabled");
			 	},
			 	dataType : "json",
			 	contentType : 'application/json; charset=UTF-8',
			 	success:function(data){
			 		
			 		if(data.code == 200){
			 			new $.zui.Messager('修改成功!', {icon:'check' ,type: 'success',placement: 'center',time:'2000'}).show();
			 			SysDictListPage.findSysDictList();
			 			$(".closeWindowBtn").click();
			 			return;
			 		}
			 		
			 		new $.zui.Messager(data.message, {icon:'times',type: 'danger',placement: 'center',time:'2000'}).show();
			 		
			 	}		
			 });
	    	
	    }
	    
}

$(function(){
	
	//初始化
	SysDictListPage.init();
	
	//初始化表格
	SysDictListPage.pagingTooler.initTableList();
	
});
